<?php
class Tourism_profit_rate_model extends BZ_Model
{
    protected $table = 'tourism_profit_rate';
    
     /**
     * 总共
     * @param unknown $param
     */
    public function total($param=array()) {
    	
        $this->db->where('logic_delete',1);
        $this->db->where('uid',$param['uid']);
        return $this->db->count_all_results($this->table);
    }
    
     /**
     * 发现
     * @param unknown $param
     * @param string $f
     */
    public function findByParam($param=array(), $f='*')
    {
        $this->db->select($f);
        if (!empty($param['rate_id'])) {
            $this->db->where('rate_id',$param['rate_id']);
        }
        if (!empty($param['uid'])) {
            if (is_array($param['uid'])){
                $this->db->where_in('uid',$param['uid']);
            }else {
                $this->db->where('uid',$param['uid']);
            }
        }
        return $this->db->get($this->table);
    }
    
     /**
      *  列表
     * @param unknown $param
     */
    public function page_list($page_num, $num,$param=array(),$f='*') {
    	
        $this->db->select($f);
        $this->db->from($this->table);
        $this->db->where('logic_delete',1);
        $this->db->where('uid',$param['uid']);
        $this->db->limit($page_num, $num);
        $this->db->order_by('rate_id','desc');
        return $this->db->get();
    }
    
     /**
     * 逻辑删除
     * @param unknown $rate_id
     */
    public function logicDelete($rate_id) {
    	
        $data['logic_delete'] = 2;
        $this->db->where('rate_id',$rate_id);
        return $this->db->update($this->table,$data);
    }
    
     /**
     * 编辑
     */
    public function updateBak($param)
    {
        if (isset($param['name'])) {
        	$data['name'] = $param['name'];
        }
        if (isset($param['prosecond'])) {
            $data['prosecond'] = $param['prosecond'];
        }
        if (isset($param['purchaser'])) {
            $data['purchaser'] = $param['purchaser'];
        }
        if (isset($param['purchaser_city'])) {
            $data['purchaser_city'] = $param['purchaser_city'];
        }
        if (isset($param['beizhu'])) {
            $data['beizhu'] = $param['beizhu'];
        }
        if (isset($param['manager_l1'])) {
            $data['manager_l1'] = $param['manager_l1'];
        }
        if (isset($param['manager_l2'])) {
            $data['manager_l2'] = $param['manager_l2'];
        }
        if (isset($param['growth'])) {
            $data['growth'] = $param['growth'];
        }
        if (isset($param['seller'])) {
            $data['seller'] = $param['seller'];
        }
        if (isset($param['uid'])) {  //供应商UID
            $data['uid'] = $param['uid'];
        }
        if (isset($param['prosecond_id'])) {  //二级供应商UID
            $data['prosecond_id'] = $param['prosecond_id'];
        }
        if (isset($param['purchaser_id'])) { //采购省代
            $data['purchaser_id'] = $param['purchaser_id'];
        }
        if (isset($param['purchaser_city_id'])) { //采购市代
            $data['purchaser_city_id'] = $param['purchaser_city_id'];
        }
        if (isset($param['manager_l1_id'])) { //省级代理商
            $data['manager_l1_id'] = $param['manager_l1_id'];
        }
        if (isset($param['manager_l2_id'])) { //市级代理市代
            $data['manager_l2_id'] = $param['manager_l2_id'];
        }
        if (isset($param['growth_id'])) { //发展商ID
            $data['growth_id'] = $param['growth_id'];
        }
        if (isset($param['seller_id'])) { //分销商ID
            $data['seller_id'] = $param['seller_id'];
        }
        $this->db->where('rate_id',$param['rate_id']);
        return $this->db->update($this->table,$data);
    }
    
}